package analyzeLogFiles;

import java.io.*;
import java.net.*;
import java.util.*;

/**
 * AnalzyeLogsServer
 * @author Gabrielle DuBois
 * @author anonymous
 *
 */
class AnalzyeLogsServer {
/*
    private static Vector clientList = new Vector (4,4);
    private static int id = 0;

    public static void main (String [] args) throws IOException {
		//Get the port and created a socket there.
		int port = 8190;
		if (args.length > 0)
			port = Integer.parseInt(args[0]);
		ServerSocket listener = new ServerSocket(port);
		System.out.println("The Chat Server is running on port " + port);

		// Listen for clients. Start a new handler for each.
		// Add each client to the linked list.
		while (true) {
			Socket client = listener.accept();
			new ChatHandler(client).start();
			System.out.println("New client no."+id+
					   " on client's port "+client.getPort());
			clientList.addElement(client);
			id++;
		}
    }//main()

    static synchronized void broadcast(String message, String name) throws IOException {
		// Sends the message to every client including the sender.
		Socket s;
		PrintWriter p;
		for (int k = 0; k < clientList.size(); k++) {
			s = (Socket) clientList.elementAt(k);
			p = new PrintWriter(s.getOutputStream(), true);
			p.println(name + ": "+message);
		}
    }//broadcast()

    static synchronized void remove (Socket s) {
		// Finds the client on the list (by comparing socket
		// references) and removes it.
		int k;
		Socket t;
		for (k = 0; k < clientList.size(); k++) {
			t = (Socket) clientList.elementAt(k);
			if (t.equals(s)) break;
		}
		clientList.removeElementAt(k);
		id--;
    }//remove()

}//AnalzyeLogsServer

class ServerHandler extends Thread {

    // The ServerHandler class is called from the AnalzyeLogsServer:
    // one thread for each client server coming.

    private BufferedReader in;
    private PrintWriter out;
    private Socket toClient;
    private String name;

    ServerHandler (Socket s) {
		toClient = s;
    }

    public void run () {
		try {

			// Create i-o streams through the socket we were
			// given when the thread was instantiated

			out = new PrintWriter(toClient.getOutputStream(), true);
			in = new BufferedReader
			(new InputStreamReader ( (toClient.getInputStream())));
			out.println(new String("*** Welcome to Chatter ***"));
			out.println(new String("Type BYE to end"));
			out.println(new String("What is your name? "));
			String name = in.readLine();
			ChatServer.broadcast(name+" has joined the discussion.","Chatter");

			// Read lines and send them off for broadcasting.
			while (true) {
			String s = in.readLine ().trim();
			System.out.println(s);
			// Check first three characters for BYE.
			// Avoids problems with different line end characters.
			if (s.charAt(0)=='B' && s.charAt(1)=='Y' && s.charAt(2)=='E') {
				ChatServer.broadcast(name+" has left the discussion.","Chatter");
				break;
			}
			ChatServer.broadcast(s,name);
			}
			ChatServer.remove(toClient);
			toClient.close();
		}
		catch (Exception e) {System.out.println("Chatter error: "+e);}
    }
*/
}//ServerHandler





